home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
memory
/
addram10.zip
/
SUBRAM.ASM
< prev
next >
Wrap
Assembly Source File
|
1989-02-14
|
7KB
|
232 lines
; Copyright (c) 1989 by Marty Del Vecchio for personal use only.
; May not be sold under any circumstances. For questions call me
; at (508) 820-1544, or the Channel 1 BBS at (617) 354-8873).
;
; To create SUBRAM.COM, you must assemble this file:
;
; MASM subram;
;
; then link it to an executable:
;
; LINK subram;
;
; then turn it into a .COM file:
;
; EXE2BIN sybram.exe subram.com
;
; then delete the .EXE file:
;
; DEL subram.exe
;
;
get_vector equ 35h
emm_int equ 67h
EMM_name_length equ 8
code_seg_a segment
assume cs:code_seg_a, ds:code_seg_a
org 100h
subram proc far
start: jmp begin
copyrt db 0Dh, 0Ah
db 'SUBRAM 1.00 Copyright (C) 1989 by Marty Del Vecchio', 0Dh, 0Ah, 00h
have_640_msg db 'Only 640KB DOS memory--no memory had been added by ADDRAM.', 0Dh, 0Ah, 00h
mem_reset_msg db 'DOS memory reset to 640KB, EMS memory freed.', 0Dh, 0Ah, 00h
no_EMM_msg db 'Expanded Memory Manager not found--no EMS installed.', 0Dh, 0Ah, 00h
no_name_msg db 'No memory had been added by ADDRAM.', 0Dh, 0Ah, 00h
not_last_msg db 'This program''s memory allocation block is not the last', 0Dh, 0Ah
db 'in DOS''s chain. Cannot change memory if not at end.', 0Dh, 0Ah, 00h
free_err_msg db 'Error deallocating EMS memory.', 0Dh, 0Ah, 00h
EMM_name db 'EMMXXXX0'
handle_name db 'ADDRAM00' ; 8 characters, pad with 0
handle dw 0 ; EMS handle
pages dw 0 ; Number of pages owned by handle
begin: call say_hello ; Print messages
call check_640 ; See if already 640K
jc error_exit
call check_EMM ; Can we find our handle?
jc error_exit
call check_MCB ; Is MCB last in chain?
jc error_exit
call tell_DOS ; Convince DOS there is less memory
jc error_exit
call free_handle ; Free EMS handle and its pages
jc error_exit
success_exit: mov ax, 4C00h ; Terminate, signal success
int 21h
error_exit: mov ax, 4C01h ; Terminate, signal failure
int 21h
subram endp
say_hello PROC near
mov si, offset copyrt
call printf_si
ret
say_hello ENDP
check_640 PROC near
push ds
mov ax, 40h ; Accessing BIOS area
mov ds, ax
mov ax, ds:[0013h] ; Get # of KB from BIOS
pop ds
cmp ax, 640 ; Is it 640K right now?
je is_640 ; Yes, error!
not_640: clc ; No, signal OK
jmp check_640_exit
is_640: mov si, offset have_640_msg
call printf_si
stc
check_640_exit: ret
check_640 ENDP
check_EMM PROC near
mov ah, get_vector ; First check if EMM here
mov al, emm_int
int 21h
mov di, 0Ah
lea si, EMM_name ; Compare name
mov cx, EMM_name_length
cld
repe cmpsb
jne not_installed ; Not installed
EMM_installed: mov ax, 5401h ; Check if handle exists
mov si, offset handle_name
int 67h
or ah, ah ; Return OK?
jnz name_not_found ; Yes, handle in dx
name_found: mov word ptr handle, dx ; Store handle
mov ah, 4Ch ; Find # of pages owned
int 67h
mov word ptr pages, bx ; Store # of pages owned
clc ; Signal success
jmp check_EMM_exit ; Exit!
not_installed: mov si, offset no_EMM_msg ; EMM not found
call printf_si
stc
jmp check_EMM_exit
name_not_found: mov si, offset no_name_msg ; Handle name not found
call printf_si
stc
check_EMM_exit: ret
check_EMM ENDP
check_MCB PROC near
push ds
mov ax, cs ; Point to MCB for this blcok
dec ax
mov ds, ax
mov al, ds:0000 ; Retrieve first byte
pop ds
cmp al, 5Ah ; 5Ah for last, 4Dh for not last
jnz not_last
is_last: clc
jmp check_MCB_exit
not_last: mov si, offset not_last_msg
call printf_si
stc
check_MCB_exit: ret
check_MCB ENDP
tell_DOS PROC near
push ds
mov ax, ds ; Make sure ES=DS
mov es, ax
get_pages: mov ax, word ptr pages ; # of pages added by ADDRAM
mov cl, 0Ah
shl ax, cl ; AX = # of paragraphs added
mov dx, cs ; Address MCB
dec dx
mov ds, dx
sub ds:0003, ax ; Change MCB
sub es:0002, ax ; Change PSP
mov cl, 6
shr ax, cl ; ax = KB added
mov dx, 40h
mov ds, dx
sub ds:0013, ax ; Change BIOS
pop ds
mov si, offset mem_reset_msg
call printf_si
clc
tell_DOS_exit: ret
tell_DOS ENDP
free_handle PROC near
mov ah, 45h ; Deallocate pages
mov dx, word ptr handle ; Retrieve handle #
int 67h
or ah, ah ; Error?
jz free_OK
free_fail: mov si, offset free_err_msg
call printf_si
stc
jmp free_exit
free_OK: clc
free_exit: ret
free_handle ENDP
printf_si PROC near
mov ah, 06h ; DOS function 06h, console output
next_char: lodsb ; Next char into al
or al, al ; Is it zero?
jz printf_done ; Yes, exit
mov dl, al ; Put char into dl
int 21h ; Output character
jmp next_char ; Loop to next character
printf_done: ret
printf_si ENDP
code_seg_a ends
end start